class Course < ActiveRecord::Base
	
	belongs_to :semester

# Attribute names to display for errors
# --------------------------------

HUMANIZED_ATTRIBUTES = {
	:name =>		"Course name",
	:required_ta => "Number of TAs required"
}
def self.human_attribute_name(attr)
	HUMANIZED_ATTRIBUTES[attr.to_sym] || super
end


# Validation for Courses 
# --------------------------------

validates_uniqueness_of 	:name, 			:scope => :semester_id
validates_format_of 		:name, 			:with => /^([A-Za-z]{4}\d{3})?$/, 	:message => "is not valid, it must be four (4) letters followed by three (3) numbers. ex: cmsc132"
validates_numericality_of 	:required_ta, 	:on => :create, 					:only_integer => true

def validate
	if required_ta % 5 != 0 
		errors.add_to_base("The requred TA's is not valid, it must be divisible by 5.")
	end
end

end
